package chap10collection.test23;

import java.util.*;

/**
 * @author zdl
 * @date 2024/12/17
 */
class Student {
    private String name;
    private int age;
    private double score;
    private String classNum;

    public Student() {
    }

    public Student(String name, int age, double score, String classNum) {
        this.name = name;
        this.age = age;
        this.score = score;
        this.classNum = classNum;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     *
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     *
     * @return score
     */
    public double getScore() {
        return score;
    }

    /**
     * 设置
     *
     * @param score
     */
    public void setScore(double score) {
        this.score = score;
    }

    /**
     * 获取
     *
     * @return classNum
     */
    public String getClassNum() {
        return classNum;
    }

    /**
     * 设置
     *
     * @param classNum
     */
    public void setClassNum(String classNum) {
        this.classNum = classNum;
    }

    public String toString() {
        return "Student{name = " + name + ", age = " + age + ", score = " + score + ", classNum = " + classNum + "}";
    }
}

public class Demo23 {
    public static void main(String[] args) {
        List<Student> list = new ArrayList();
        list.add(new Student("Tom", 18, 100, "class05"));
        list.add(new Student("Jerry", 22, 70, "class04"));
        list.add(new Student("Owen", 25, 90, "class05"));
        list.add(new Student("Jim", 30, 80, "class05"));
        list.add(new Student("Steve", 28, 66, "class06"));
        list.add(new Student("Kevin", 24, 100, "class04"));
        Map<String,List<Student>> map = new HashMap<>();
       //计算所有学生的平均年龄
        double sumAge = 0;
        for (Student student : list) {
            sumAge += student.getAge();
        }
        double avgAge = sumAge / list.size();
        System.out.println("平均年龄:" + avgAge);
        //计算各个班级的平均分


    }
}
